package UseString.demo06;

import UseString.demo02.StringReverse;

import java.util.StringJoiner;

public class Practice {
    public static void main(String[] args) {
        // 第一个练习字符串有哪些问题
        question04();
    }
    public static void question01(){
        // 问题一: 字符串下有哪些的问题
        String q1 = "1.字符串的定义\n";
        String q2 = "2.字符串的比较\n";
        String q3 = "3.字符串中的方法\n";
        String q4 = "4.字符串的格式化输出\n";
        String q5 = q1+q2+q3+q4;
        System.out.println(q5);
    }

    public static void question02(){
        // 问题二: 字符串的定义？
        // 三个对象String StringBuilder StringJoiner对象
        String s1 = "直接赋值的"; // 直接复制和new出来的区别
        String s2 = new String("new出来的");
        System.out.println(s1);
        System.out.println(s2);
        // StringBuilder对象
        StringBuilder s3 = new StringBuilder();
        s3.append("123");
        int length = s3.length();
        System.out.println(length);
        s3.reverse();
        System.out.println(s3);
        String string = s3.toString();
        System.out.println(string);
        // StringJoiner对象
        StringJoiner sj = new StringJoiner(",","[","]");
        sj.add("parate");
        sj.add("perate");
        sj.add("porate");
        sj.add("berate");
        sj.add("borate");
        int length1 = sj.length();
        System.out.println(length1);
        String string1 = sj.toString();
        System.out.println(string1);
    }
    public static void question03(){
        // 问题三: 字符串的比较
        String s1 = "==,引用类型比较地址值，基础数据比较的是值";
        String s2 = "equal,比较是地址值";
        String s3 = "separate";
        String s4 = new String("separate");
        boolean equals = s3.equals(s4);
        System.out.println(equals);
    }
    public static void question04(){
        // 问题四: 字符串中的方法？
        String parate = "separate separable separation disparate";
        String s = parate.replace(" ", "-");
        System.out.println(parate);
        System.out.println(s);
        System.out.println(parate.length());
        System.out.println(parate.startsWith("separate"));
        for (int i = parate.toCharArray().length - 1; i >= 0; i--) {
            System.out.println(parate.toCharArray()[i]);
        }

    }

}
